﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EffectManager
{
    private Dictionary<string, GameObject> _effectDic = new Dictionary<string, GameObject>();
    private static EffectManager _instance;
    public static EffectManager Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new EffectManager();
            }
            return _instance;
        }
    }

    public void PlayEffect(string name, Vector3 position, Quaternion rotation, float time)
    {
        if (!_effectDic.ContainsKey(name))
        {
            string path = "Assets/Prefabs/Effect/" + name + ".prefab";
            GameObject EffectPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
            _effectDic.Add(name, EffectPrefab);
        }

        GameObject effect = GameObject.Instantiate(_effectDic[name]);
        effect.transform.position = position;
        effect.transform.rotation = rotation;
        GameObject.Destroy(effect, time);
    }

}
